package com.jt.controller;

import com.jt.annotation.Logable;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CacheDemoController02 {
    //private static final Logger log = LoggerFactory.getLogger(CacheDemoController02.class);
    /**
     * 底层就是AOP,由此注解描述的方法为一个切入点方法,
     * 这个方法在执行时.会通过代理对象进行缓存功能增强,
     * @Cacheable注解, 含义是告诉底层系统,将方法的返回值存储到Cache中(配置文件配置了redis集群)
     *
     * 简单来说,就是方法执行完,要不要存入到缓存
     */
    @Logable
    @Cacheable(value = "demo2")
    @GetMapping("/demo2/hello")
    public String doSayHello() {
        //log.info("start:"+System.currentTimeMillis());
        System.out.println("==Get Hello From Mysql==");
        String result = "Hello redis";
        //log.info("end:"+System.currentTimeMillis());
        return result;
    }
}


/*
class SubClass extends CacheDemoController02 {
    @Autowired
    private RedisTemplate redisTemplate;
    private Object result;

    @Override
    public String doSayHello() {
        redisTemplate.opsForValue().get(result);
        return super.doSayHello();
    }
}*/
